package org.huntaway.kindergarten.common;

import java.util.HashMap;
import java.util.Map;

import org.huntaway.kindergarten.manager.BaseMng;
import org.huntaway.kindergarten.manager.ClassInfoMng;
import org.huntaway.kindergarten.manager.DictMng;
import org.huntaway.kindergarten.manager.DutyMng;
import org.huntaway.kindergarten.manager.FinanceDefineMng;
import org.huntaway.kindergarten.manager.FinanceTypeMng;
import org.huntaway.kindergarten.manager.GenearchMng;
import org.huntaway.kindergarten.manager.InDefineMng;
import org.huntaway.kindergarten.manager.IncomeMng;
import org.huntaway.kindergarten.manager.JournalMng;
import org.huntaway.kindergarten.manager.OutDefineMng;
import org.huntaway.kindergarten.manager.PayoutMng;
import org.huntaway.kindergarten.manager.PersonMng;
import org.huntaway.kindergarten.manager.StudentInfoMng;
import org.huntaway.kindergarten.manager.StudentMng;
import org.huntaway.kindergarten.manager.TeacherGroupMng;
import org.huntaway.kindergarten.manager.TeacherMng;
import org.huntaway.kindergarten.manager.TimeBookMng;
import org.huntaway.kindergarten.manager.UserMng;
import org.huntaway.kindergarten.service.bi.funds.GeneralledgerService;
import org.huntaway.kindergarten.service.bi.funds.IncomeService;
import org.huntaway.kindergarten.service.bi.funds.PayoutService;
import org.huntaway.kindergarten.service.bi.funds.WasteBookService;
import org.huntaway.kindergarten.service.bi.student.StudentInfoService;
import org.huntaway.kindergarten.service.bi.student.TimeBookService;
import org.huntaway.kindergarten.service.common.ClassInfoSeleService;
import org.huntaway.kindergarten.service.common.DutySeleService;
import org.huntaway.kindergarten.service.common.GenearchSeleService;
import org.huntaway.kindergarten.service.common.InDefineSeleService;
import org.huntaway.kindergarten.service.common.LoginService;
import org.huntaway.kindergarten.service.common.OutDefineSeleService;
import org.huntaway.kindergarten.service.common.PersonSeleService;
import org.huntaway.kindergarten.service.common.StudentSeleService;
import org.huntaway.kindergarten.service.common.TeacherGroupSeleService;
import org.huntaway.kindergarten.service.common.TeacherSeleService;
import org.huntaway.kindergarten.service.daily.GenearchService;
import org.huntaway.kindergarten.service.daily.PersonService;
import org.huntaway.kindergarten.service.daily.StudentService;
import org.huntaway.kindergarten.service.daily.TeacherService;
import org.huntaway.kindergarten.service.info.ClassInfoService;
import org.huntaway.kindergarten.service.info.DutyService;
import org.huntaway.kindergarten.service.info.InDefineService;
import org.huntaway.kindergarten.service.info.OutDefineService;
import org.huntaway.kindergarten.service.info.TeacherGroupService;
import org.huntaway.kindergarten.service.system.DictService;
import org.huntaway.kindergarten.service.system.UserService;
import org.huntaway.kindergarten.util.GlobalCon;
import org.huntaway.struts1.preprocessor.Preprocessor;

public class SingletonManager {
	private static Map<String, Preprocessor> serviceMap = new HashMap<String, Preprocessor>();
	static {
		initServiceMap();
	}

	private static void initServiceMap() {
		serviceMap.put("kindergarten.funds.generalledger",
				new GeneralledgerService());
		serviceMap.put("kindergarten.funds.income", new IncomeService());
		serviceMap.put("kindergarten.funds.payout", new PayoutService());
		serviceMap.put("kindergarten.funds.wastebook", new WasteBookService());
		serviceMap.put("kindergarten.student.studentinfo",
				new StudentInfoService());
		serviceMap.put("kindergarten.student.timebook", new TimeBookService());

		serviceMap.put("kindergarten.daily.genearch", new GenearchService());
		serviceMap.put("kindergarten.daily.person", new PersonService());
		serviceMap.put("kindergarten.daily.student", new StudentService());
		serviceMap.put("kindergarten.daily.teacher", new TeacherService());

		serviceMap.put("kindergarten.info.classinfo", new ClassInfoService());
		serviceMap.put("kindergarten.info.duty", new DutyService());

		serviceMap.put("kindergarten.info.teachergroup",
				new TeacherGroupService());
		serviceMap.put("kindergarten.info.indefine", new InDefineService());
		serviceMap.put("kindergarten.info.outdefine", new OutDefineService());

		serviceMap.put("kindergarten.system.dict", new DictService());
		serviceMap.put("kindergarten.system.user", new UserService());

		serviceMap.put("admin.system.dict", new DictService());
		serviceMap.put("admin.system.user", new UserService());

		serviceMap.put("login", new LoginService());		
		
		serviceMap.put("kindergarten.select.genearch", new GenearchSeleService());
		serviceMap.put("kindergarten.select.person", new PersonSeleService());
		serviceMap.put("kindergarten.select.student", new StudentSeleService());
		serviceMap.put("kindergarten.select.teacher", new TeacherSeleService());
		serviceMap.put("kindergarten.select.classinfo", new ClassInfoSeleService());
		serviceMap.put("kindergarten.select.duty", new DutySeleService());

		serviceMap.put("kindergarten.select.teachergroup",
				new TeacherGroupSeleService());
		serviceMap.put("kindergarten.select.indefine", new InDefineSeleService());
		serviceMap.put("kindergarten.select.outdefine", new OutDefineSeleService());
		
	}

	private static Map<String, BaseMng<?>> mngMap = new HashMap<String, BaseMng<?>>();
	static {
		initMngMap();
	}

	private static void initMngMap() {
		mngMap.put(GlobalCon.CLASS_INFO, new ClassInfoMng());
		mngMap.put(GlobalCon.TEACHER_GROUP, new TeacherGroupMng());
		mngMap.put(GlobalCon.TEACHER, new TeacherMng());
		mngMap.put(GlobalCon.GENEARCH, new GenearchMng());
		mngMap.put(GlobalCon.DUTY, new DutyMng());
		mngMap.put(GlobalCon.STUDENT, new StudentMng());
		mngMap.put(GlobalCon.JOURNAL, new JournalMng());
		mngMap.put(GlobalCon.INDEFINE, new InDefineMng());
		mngMap.put(GlobalCon.OUTDEFINE, new OutDefineMng());
		mngMap.put(GlobalCon.INCOME, new IncomeMng());
		mngMap.put(GlobalCon.PAYOUT, new PayoutMng());
		mngMap.put(GlobalCon.STUDENTINFO, new StudentInfoMng());
		mngMap.put(GlobalCon.TIMEBOOK, new TimeBookMng());
		
		mngMap.put(GlobalCon.PERSON, new PersonMng());
		
		mngMap.put(GlobalCon.USER, new UserMng());
		mngMap.put(GlobalCon.DICT, new DictMng());
		
		mngMap.put(GlobalCon.FINANCETYPE, new FinanceTypeMng());
		mngMap.put(GlobalCon.FINANCEDEFINE, new FinanceDefineMng());

	}

	private SingletonManager() {
	}

	// 在自己内部定义自己一个实例，是不是很奇怪？
	// 注意这是private 只供内部调用

	private static SingletonManager instance = new SingletonManager();

	// 这里提供了一个供外部访问本class的静态方法，可以直接访问
	public static SingletonManager getInstance() {
		if (instance == null)
			instance = new SingletonManager();
		return instance;
	}

	public static void setServiceMap(Map<String, Preprocessor> serviceMap) {
		SingletonManager.serviceMap = serviceMap;
	}

	public Map<String, Preprocessor> getServiceMap() {
		return serviceMap;
	}

	public Preprocessor getService(String serviceName) {
		if (serviceMap == null) {
			serviceMap = new HashMap<String, Preprocessor>();
			initServiceMap();
		}
		return serviceMap.get(serviceName);
	}

	public BaseMng<?> getMng(String MngName) {
		if (mngMap == null) {
			mngMap = new HashMap<String, BaseMng<?>>();
			initMngMap();
		}
		return mngMap.get(MngName);
	}
}
